import java.util.ArrayList;


public class YahtzeeCategoryChecker implements YahtzeeConstants{
	
	private int[] diceRoll;
	private int category;
	private int[][] numberRepetition;
	
	public YahtzeeCategoryChecker(int[] diceRoll, int category){
		this.diceRoll = diceRoll;
		this.category = category;
		
		setNumberRepetition();
	}	
	
	public int getNumberRepetition(int category){
		return numberRepetition[category][1];
	}
	
	private void setNumberRepetition(){
		numberRepetition = new int [6][2];
		for (int i=0; i<N_DICE; i++){
			numberRepetition[(diceRoll[i]-1)][1]++;
		}
	}
	
	public boolean isSimple(){
		return category >= ONES && category <= SIXES;
	}
	
	public boolean isThreeOfAKind(){
		if (category==THREE_OF_A_KIND){
			
			boolean foundThrees = false;
			
			for (int i=0; i<diceRoll.length; i++){
				if (numberRepetition[i][1] >= 3){
					foundThrees = true;
				}
			}
			
			return foundThrees;
		}
		
		return false;
	}
	
	public boolean isFourOfAKind(){
		if (category==FOUR_OF_A_KIND){
			
			boolean foundFours = false;
			
			for (int i=0; i<diceRoll.length; i++){
				if (numberRepetition[i][1] >= 4){
					foundFours = true;
				}
			}
			
			return foundFours;
		}
		
		return false;
	}
	
	public boolean isYahtzee(){
		if (category==YAHTZEE){
			
			boolean foundYahtzee = false;
			
			for (int i=0; i<diceRoll.length; i++){
				if (numberRepetition[i][1] == 5){
					foundYahtzee = true;
				}
			}
			
			return foundYahtzee;
		}
		
		return false;
	}
	
	public boolean isFullHouse(){
		if (category==FULL_HOUSE){
		
			boolean foundThrees = false;
			boolean foundTwos = false;
			
			for (int i=0; i<=diceRoll.length; i++){
				if (numberRepetition[i][1] == 3){
					foundThrees = true;
				}
				if (numberRepetition[i][1] == 2){
					foundTwos = true;
				}
			}
			
			return foundThrees && foundTwos;
		}
		
		return false;
	}
	
	public boolean isLargeStraight(){
		if (category==LARGE_STRAIGHT){
			return checkStraight(0, 4) || checkStraight(1, 5);
		}
		
		return false;
	}
	
	public boolean isSmallStraight(){
		if (category==SMALL_STRAIGHT){
			return checkStraight(0, 3) 
				|| checkStraight(1, 4)
				|| checkStraight(2, 5);
		}
		
		return false;
	}	
	
	private boolean checkStraight(int start, int end){
		boolean isStraight = true;
		
		for (int i=start; i<end; i++)
		{
			isStraight &= numberRepetition[i][1]==1; 
		}
		
		return isStraight;
	}
}
